using System.ComponentModel.DataAnnotations;

namespace Lotto.Domain.Entitys;

public abstract class EntityBase
{
    public Guid Id { get; protected set; } = Guid.NewGuid();
    public DateTime CreatedAt { get; protected set; } = DateTime.UtcNow;
    public Guid? CreatedBy { get; protected set; }
    public DateTime? UpdatedAt { get; protected set; }
    public Guid? UpdatedBy { get; protected set; }
    public bool IsDeleted { get; protected set; } = false;
    [Timestamp]
    public byte[]? RowVersion { get; protected set; }
    public string? Remark { get; protected set; }
    public bool IsActive { get; protected set; } = true;

    /// <summary>
    /// 设置创建人
    /// </summary>
    public void SetCreatedBy(Guid userId)
    {
        CreatedBy = userId;
    }

    /// <summary>
    /// 修改更新时间和修改人
    /// </summary>
    public void SetUpdated(Guid userId)
    {
        UpdatedAt = DateTime.UtcNow;
        UpdatedBy = userId;
    }

    /// <summary>
    /// 软删除
    /// </summary>
    public void Delete()
    {
        IsDeleted = true;
    }

    /// <summary>
    /// 修改备注
    /// </summary>
    public void SetRemark(string? remark)
    {
        Remark = remark;
    }

    /// <summary>
    /// 启用
    /// </summary>
    public void Activate()
    {
        IsActive = true;
    }

    /// <summary>
    /// 禁用
    /// </summary>
    public void Deactivate()
    {
        IsActive = false;
    }
}

